package com.tanhua.server.controller;

import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    /**
     * 消息-添加联系人
     * POST /messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        Long userId = Long.valueOf(map.get("userId").toString());
        return messagesService.contacts(userId);
    }

    /**
     * 消息-联系人列表
     * GET /messages/contacts
     */
    @GetMapping("/contacts")
    public ResponseEntity findContacts(@RequestParam(defaultValue = "1") int page,
                                       @RequestParam(defaultValue = "10") int pagesize,
                                       @RequestParam(required = false) String keyword) {
        return messagesService.findContacts(page, pagesize, keyword);
    }

    /**
     * 消息-点赞列表 （点赞commentType:1）
     * GET /messages/likes
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") int page,
                                @RequestParam(defaultValue = "10") int pagesize) {
       return messagesService.findCommentList(1,page, pagesize);
    }
    /**
     * 消息-评论列表（评论commentType:2）
     * GET /messages/comments
     */
    @GetMapping("/comments")
    public ResponseEntity findCommentsList(@RequestParam(defaultValue = "1")int page,
                                           @RequestParam(defaultValue = "10")int pagesize){
        return messagesService.findCommentList(2, page, pagesize);
    }

    /**
     * 消息-喜欢列表（喜欢commentType:3）
     * GET /messages/loves
     */
    @GetMapping("/loves")
    public ResponseEntity findLoveList(@RequestParam(defaultValue = "1")int page,
                                       @RequestParam(defaultValue = "10")int pagesize){
        return messagesService.findCommentList(3, page, pagesize);
    }

    /**
     * 消息-公告列表
     * GET /messages/announcements
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") int page,
                                        @RequestParam(defaultValue = "10") int pagesize) {
        return messagesService.announcements(page, pagesize);
    }
}


